package org.xu.logic;

import com.core.utils.HttpFormUtil;
import com.core.utils.UUIDGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xu.entity.WorkFlowLogEntity;
import org.xu.enums.WorkTypeEnum;
import org.xu.service.WorkFlowLogService;

import java.util.Date;

@Slf4j
@Service
public class SignLogicImpl implements SignLogic{

    @Autowired
    private WorkFlowLogService workFlowLogService;

    private static final String dataIdStr = "signIn_robot";

    public void acquireFood(String key,String token) {
       // log.info("token:{}",token);
        StringBuffer sbf = new StringBuffer();
        sbf.append("------WebKitFormBoundaryKF0ZAvnkUttfD536\r\n")
                .append("Content-Disposition: form-data; name=\"token\"\r\n")
                .append("\r\n")
                .append(token.trim())
                .append("\r\n------WebKitFormBoundaryKF0ZAvnkUttfD536--");
    //    System.out.println("获取点击次数，入参:");
    //    System.out.println(sbf.toString());
        String urlString = "https://h5up.bluebirdh5.top/sq/YxDecennial/myAlmond";
        String response = HttpFormUtil.formCommit("机器人页面food登录",urlString, sbf.toString(), "----WebKitFormBoundaryKF0ZAvnkUttfD536");
        if (!"失败".equals(response)){
            // 构建表单数据
            WorkFlowLogEntity entity = new WorkFlowLogEntity();
            entity.setId(UUIDGenerator.generate());
            entity.setDataId(dataIdStr);
            entity.setApplyNo("test_"+key);
            entity.setCreateTime(new Date());
            entity.setOperationResult(key+":登录Food获取完成");
            entity.setRemark(response);
            entity.setDeleted(false);
            entity.setWorkType(WorkTypeEnum.SIGN);
            workFlowLogService.insert(entity);
        }
    }





}
